package com.ww.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 * @desc ww
 */
@Configuration
public class RabbitDirectMqConfig {

    /**
     * Direct(路由健) 模式
     */
    private static final String DIRECT_QUEUE_01 = "direct_queue_01";
    private static final String DIRECT_QUEUE_02 = "direct_queue_02";
    private static final String DIRECT_EXCHANGE = "directExchange";
    private static final String ROUTING_KEY_01 = "queue.red";
    private static final String ROUTING_KEY_02 = "queue.green";

    @Bean
    public Queue directQueue01(){
        return new Queue(DIRECT_QUEUE_01);
    }
    @Bean
    public Queue directQueue02(){
        return new Queue(DIRECT_QUEUE_02);
    }
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    @Bean
    public Binding directBinding01() {
        return BindingBuilder.bind(directQueue01()).to(directExchange()).with(ROUTING_KEY_01);
    }

    @Bean
    public Binding directBinding02() {
        return BindingBuilder.bind(directQueue02()).to(directExchange()).with(ROUTING_KEY_02);
    }


}